package 代码记录.校招笔试真题.笔试真题_2023.水滴;

/**
 * @author zx
 * @create 2023-03-23 21:23
 * 62.5%
 */
public class Test3 {
    public char[][] simulatingGravity (char[][] mesh) {
        int hang = mesh.length;
        int lie = mesh[0].length;
        for(int i = 0;i < lie;i++){
            int p = -1,w = -1;
            int j = 0;
            for(;j < hang;j++){
                //System.out.print(mesh[j][i]);
                if(mesh[j][i] == 'o'){
                    p = j;
                }
                if(mesh[j][i] == '#'){
                    w = j;
                }
            }
            if(p != -1 && w != -1 && (p < w - 1)){//两者都有,且需下沉
                mesh[p][i] = '.';
                mesh[w - 1][i] = 'o';
            }else if(p != -1 && w == -1){//没有障碍物,直接下沉
                mesh[p][i] = '.';
                mesh[hang - 1][i] = 'o';
            }else if(p == -1 && w == -1){
                continue;
            }else if(p == -1 && w != -1){
                continue;
            }
        }
        return mesh;
    }

    /**
    public char[][] simulatingGravity (char[][] mesh) {
        int hang = mesh.length;
        int lie = mesh[0].length;
        for(int i = 0;i < lie;i++){
            for(int j = 0;j < hang;j++){
                System.out.print(mesh[j][i]);
            }
            System.out.println();
        }
        return mesh;
    }
     */
}
